package com.mspbots.core.wise.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mspbots.core.AbstractBaseController;
import com.mspbots.core.wise.model.TenantUserConfiguration;
import com.mspbots.core.wise.service.TenantUserConfigurationService;
import com.mspbots.cw.request.TenantUserConfigurationDTO;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * <p>
 *
 * </p>
 *
 * @author Jun Zhou
 * @since 2019-06-24
 */
@RestController
@RequestMapping("{tenant}/user-configuration")
public class TenantUserConfigurationController extends AbstractBaseController<TenantUserConfiguration, TenantUserConfigurationService> {

    @GetMapping(path = "/workTimePage")
    public Callable configPage(Page<TenantUserConfigurationDTO> page, TenantUserConfiguration query) {
        return () -> service.workTimePage(page, query);
    }

    @GetMapping(path = "/workTimeList")
    public Callable workTimeList(TenantUserConfiguration query) {
        return () -> service.workTimeList(query);
    }

    @GetMapping(path = "/keyword/{keyword}")
    public Callable selectByTenantUserId(@RequestParam("tenantId") Long tenantId,
                                         @RequestParam("tenantUserId") Long tenantUserId,
                                         @PathVariable String keyword) {
        TenantUserConfiguration tenantUserConfiguration = new TenantUserConfiguration();
        tenantUserConfiguration.setTenantId(tenantId);
        tenantUserConfiguration.setTenantUserId(tenantUserId);
        tenantUserConfiguration.setKeyword(keyword);
        return () -> service.findByKeyword(tenantUserConfiguration);
    }


    @PostMapping(path = "/saveUserDaylightTime")
    public Callable saveUserDaylightTime(@RequestBody TenantUserConfiguration dto) {
        return () -> service.saveUserDaylightTime(dto);
    }

    @PostMapping(path = "/save")
    public Callable saveOrUpdate(@RequestBody TenantUserConfiguration dto) {
        return () -> service.insertOrUpdate(dto);
    }

    @PostMapping(path = "/saveBatch")
    public Callable saveOrUpdateBatch(@RequestBody List<TenantUserConfiguration> list) {
        return () -> service.insertOrUpdateBatch(list);
    }

    @GetMapping(path = "/deleteWorkTime")
    public Callable deleteWorkTime(@RequestParam("userList") List<Long> userList) {
        return () -> service.deleteWorkTime(userList);
    }
}

